package Pokero;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;




public class PlayerFrame extends JFrame implements ActionListener {
                private JFrame frame; 
        private JButton one;
        private JButton two;
        private JButton three;
        private JButton four;
        private JButton exit;
        private PokerFrame poker;
        public static  Human HumanPlayers[] = new Human[4];  // tablica przechowujaca graczy
        public static  Bot[] CPUPlayers = new Bot[3];  // tablica przechowujaca graczy
        public static int HumAmount;
        public static int CPUAmount;
        
        
        public PlayerFrame() {
                super("Pokeros");
                
                
                //window
                frame = new JFrame();
                setVisible(true);
                setSize(200, 210);
                setLayout(new FlowLayout());
                setLocationRelativeTo(null);
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                
                
                //buttons
                one = new JButton("1 gracz   "); 
                two = new JButton("2 graczy ");
                three = new JButton("3 graczy ");
                four = new JButton("4 graczy ");
                exit = new JButton("Wyjscie  ");
                
                exit.addActionListener(this);
                one.addActionListener(this);
                two.addActionListener(this);
                three.addActionListener(this);
                four.addActionListener(this);
                                
                add(one);
                add(two);
                add(three);
                add(four);
                add(exit);
                
                
                //blokada rozmiaru okna
                this.addComponentListener(new ComponentAdapter(){
            public void componentResized(ComponentEvent e){
                Dimension d=PlayerFrame.this.getSize();
                if(d.width != 200)
                    d.width=200;
                if(d.height != 210)
                    d.height=210;
                PlayerFrame.this.setSize(d);
            }
        });
        }
        
        
        @Override
        public void actionPerformed(ActionEvent e) {
                Object source = e.getSource();
                
                if(source == exit)
                	System.exit(0);
                if(source == one) {
                        
                	HumAmount = 1;
                	CPUAmount = 3;
                	HumanPlayers[0] = new Human("1", 100);
                	PokerFrame.HumanPlayers[0] = HumanPlayers[0];
                	PokerFrame.HumanPlayers[0].rozdaj();
                	
                	CPUPlayers[0] = new Bot("2", 100);
                	PokerFrame.CPUPlayers[0] = CPUPlayers[0];
                	CPUPlayers[0].rozdaj();
                	
                	CPUPlayers[1] = new Bot("3", 100);
                	PokerFrame.CPUPlayers[1] = CPUPlayers[1];
                	CPUPlayers[1].rozdaj();
                	
                	CPUPlayers[2] = new Bot("4", 100);
                	PokerFrame.CPUPlayers[2] = CPUPlayers[2];
                	CPUPlayers[2].rozdaj();
                	
                	
                	PokerFrame.pula = PokerFrame.pula + HumanPlayers[0].pobierzWpisowe();

                	PokerFrame.pula += CPUPlayers[0].pobierzWpisowe();
                	PokerFrame.pula = PokerFrame.pula + CPUPlayers[1].pobierzWpisowe();
                	PokerFrame.pula = PokerFrame.pula + CPUPlayers[2].pobierzWpisowe();
                	
                	
                	poker = new PokerFrame();
                	dispose();
                	
                }	
                
                
                if(source == two) {
                        
                	HumAmount = 2;
                	CPUAmount = 2;
                	HumanPlayers[0] = new Human("1", 100);
                	PokerFrame.HumanPlayers[0] = HumanPlayers[0];
                	PokerFrame.HumanPlayers[0].rozdaj();
                	
                	HumanPlayers[1] = new Human("2", 100);
                	PokerFrame.HumanPlayers[1] = HumanPlayers[1];
                	PokerFrame.HumanPlayers[1].rozdaj();
                	
                	CPUPlayers[0] = new Bot("CPU1", 100);
                	PokerFrame.CPUPlayers[0] = CPUPlayers[0];
                	CPUPlayers[0].rozdaj();
                	CPUPlayers[1] = new Bot("CPU2", 100);
                	PokerFrame.CPUPlayers[1] = CPUPlayers[1];
                	CPUPlayers[1].rozdaj();
                	
                	PokerFrame.pula = PokerFrame.pula + HumanPlayers[0].pobierzWpisowe();
                	PokerFrame.pula = PokerFrame.pula + HumanPlayers[1].pobierzWpisowe();
                	                	
                	PokerFrame.pula = PokerFrame.pula + CPUPlayers[0].pobierzWpisowe();
                	PokerFrame.pula = PokerFrame.pula + CPUPlayers[1].pobierzWpisowe();
                	
                	poker = new PokerFrame();
                	dispose();
                	
                }
                if(source == three) {
                        
                	HumAmount = 3;
                	CPUAmount = 1;
                    HumanPlayers[0] = new Human("1", 100);
                	PokerFrame.HumanPlayers[0] = HumanPlayers[0];
                    PokerFrame.HumanPlayers[0].rozdaj();
                    
                    HumanPlayers[1] = new Human("2", 100);
                	PokerFrame.HumanPlayers[1] = HumanPlayers[1];
                    PokerFrame.HumanPlayers[1].rozdaj();
                    
                    HumanPlayers[2] = new Human("3", 100);
                	PokerFrame.HumanPlayers[2] = HumanPlayers[2];
                    PokerFrame.HumanPlayers[2].rozdaj();
                    
                    CPUPlayers[0] = new Bot("CPU1", 100);
                    PokerFrame.CPUPlayers[0] = CPUPlayers[0];
                    PokerFrame.CPUPlayers[0].rozdaj();
                	
                    
                	PokerFrame.pula = PokerFrame.pula + CPUPlayers[0].pobierzWpisowe();
                	
                    poker = new PokerFrame();
                    dispose();
                }	
                if(source == four) {
                	
                	HumAmount = 4;
                	CPUAmount = 0;
                	HumanPlayers[0] = new Human("1", 100);
                	PokerFrame.HumanPlayers[0] = HumanPlayers[0];
                	PokerFrame.HumanPlayers[0].rozdaj();
                	
                	HumanPlayers[1] = new Human("2", 100);
                	PokerFrame.HumanPlayers[1] = HumanPlayers[1];
                	PokerFrame.HumanPlayers[1].rozdaj();
                	
                	HumanPlayers[2] = new Human("3", 100);
                	PokerFrame.HumanPlayers[2] = HumanPlayers[2];
                	PokerFrame.HumanPlayers[2].rozdaj();
                	
                	HumanPlayers[3] = new Human("4", 100);
                	PokerFrame.HumanPlayers[3] = HumanPlayers[3];
                	PokerFrame.HumanPlayers[3].rozdaj();
                	
                	dispose();
                	poker = new PokerFrame();
                }
        }
}